package com.lans.SortAlgorithm;

import java.util.Arrays;

/*
 * @author: lans
 * @date: 2025/1/20
 * @name: 刘宇
 */
public class BubblingSort1 {
    public static void main(String[] args){
        int[] arr =  new int[]{3,1,3,5,7,5,9,8};
        int[] arr1 = sort(arr);
        System.out.println(Arrays.toString(arr1));
    }
    public static int[] sort(int[] arr){
        for(int i=0;i<arr.length-1;i++){
            boolean flag = false;
            for(int j=0;j<arr.length-i-1;j++){
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = true;
                }
            }
            if(!flag){
                break;
            }
        }
        return arr;
    }
}
